package com.lee.dutylower.view.detail;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.lee.dutylower.R;
import com.lee.dutylower.db.greenEntity.Squad;

/**
 * Created by lijie on 2017/5/9.
 */

public class SquadDetailFragment extends Fragment {
    private Squad squad;
    private boolean isEditable;
    public boolean isAdd = false;
    public EditText etName;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle b = getArguments();
        if (b != null){
            squad = (Squad) b.getSerializable("Squad");
            isEditable = getArguments().getBoolean("isEditable",false);
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View v = View.inflate(getActivity(), R.layout.fragment_detail_squad,null);
        etName = (EditText) v.findViewById(R.id.et_detail_name);
        //判断是否传入了squad数据 null 即为新政数据
        if(squad == null){
            initEditableView(null);
            isAdd = true;
        }else {
            dataNotNull();
            isAdd = false;
        }
        return v;
    }

    public void dataNotNull() {

        if(isEditable){
            initEditableView(squad.getSquadName());
        }else {
            etName.setEnabled(false);
            etName.setText(squad.getSquadName());
        }
    }


    //在条件为可编辑时进行 是否新增 判断处理
    private void initEditableView(String name) {
        etName.setEnabled(true);
        if(name == null){
            etName.setHint("请输入班级");
        }else {
            etName.setText(name);
        }
    }
}
